import { http } from './http'
import { PageQueryParams, PageResponse } from '@/config/page'

export interface GroupCreateParams {
  name: string;
}

export interface GroupUpdateParams {
  name: string;
}

export interface StarDocQueryParams extends PageQueryParams {
  groupId?: number;
}

export function createGroup (params: GroupCreateParams) {
  return http().post('/api/document/doc-star-groups', params)
}

export function updateGroup (id: number, params: GroupUpdateParams) {
  return http().put(`/api/document/doc-star-groups/${id}`, params)
}

export function deleteGroup (id: number) {
  return http().delete(`/api/document/doc-star-groups/${id}`)
}

export function queryGroups () {
  return http().get('/api/document/doc-star-groups')
}

// star

export function getStarDocs (params: StarDocQueryParams) {
  return http().get<PageResponse<any>>('/api/document/doc-stars/query', { params })
}

export function star (docId: number, groupId: number) {
  return http().post<any>(`/api/document/doc-stars/doc/${docId}/group/${groupId}/create`)
}

export function unstarByDoc (docId: number) {
  return http().post<any>(`api/document/doc-stars/doc/${docId}/delete`)
}

export function unstarByGroup (groupId: number) {
  return http().post<any>(`api/document/doc-stars/group/${groupId}/delete`)
}

export function unstarByIds (ids: number[]) {
  return http().post<any>('api/document/doc-stars/delete', { ids })
}
